package org.shopen.ai.puremvc.model.domain.cities
{
	import org.shopen.ai.puremvc.model.IRavisSerializable;
	import org.shopen.ai.puremvc.model.IReadable;
	import org.shopen.ai.puremvc.model.ISerializable;
	import org.shopen.ai.puremvc.model.ITitleable;
	import org.shopen.ai.puremvc.model.utils.Convert;
	import org.shopen.ai.puremvc.model.utils.Random;

	public class City implements ISerializable, IRavisSerializable, IReadable, ITitleable
	{
		[Bindable]
		private var _id : int;
		[Bindable]
		public function get id() : int
		{
			return _id;
		}
		public function set id(value : int) : void
		{
			_id = value;
		}
		
		[Bindable]
		private var _title : String;
		[Bindable]
		public function get title() : String
		{
			return _title;
		}
		public function set title(value : String) : void
		{
			_title = value;
		}
		
		[Bindable]
		private var _x : Number = 0;
		[Bindable]
		public function get x() : Number
		{
			return _x;
		}
		public function set x(value : Number) : void
		{
			_x = value;
		}
		
		[Bindable]
		private var _y : Number = 0;
		[Bindable]
		public function get y() : Number
		{
			return _y;
		}
		public function set y(value : Number) : void
		{
			_y = value;
		}
		
		
		public function City(node : XML = null)
		{
			if (node != null)
			{
				deserialize(node);
			}
		}

		public function deserialize(node : XML) : void
		{
			if ("@id" in node)
			{
				this.id = Convert.toInt(node.@id);
			}
			else
			{
				this.id = Convert.toInt(Random.getRandomNumber(0, 10000));
			}
			if ("@title" in node)
			{
				this.title = Convert.toString(node.@title);
			}
			if ("@x" in node)
			{
				this.x = Convert.toNumber(node.@x);
			}
			if ("@y" in node)
			{
				this.y = Convert.toNumber(node.@y);
			}
		}
		
		public function serialize() : XML
		{
			// TODO: not yet implemented
			return new XML();
		}
		
		public function toRavisXml() : XML
		{
			var node : XML = new XML(<Node />);
			node.@id = this.id;
			node.@name = this.title;
			node.@desc = "city node";
			node.@nodeColor="0x00FF00";
			node.@nodeSize = 15;
			node.@nodeClass = "leaf";
			node.@nodeIcon = this.id;
			node.@x = this.x;
			node.@y = this.y;
			return node;
		}
		
		public function toString() : String
		{
			return this.title;
		}
	}
}